package com.woniuxy.userassembly.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.boot.autoconfigure.amqp.RabbitTemplateConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitProducerConfigDelay {
    public static final String EXCHANGE_NAME="EXCHANGE_SPRING_BOOT_DELAY";
    public static final String QUEUE_NAME="QUEUE_SPRING_BOOT_DELAY";
    public static final String ROUTING_NAME="ROUTING_SPRING_BOOT_DELAY";
    public static final String QUEUE_NAME1="QUEUE_SPRING_BOOT_DELAY1";
    public static final String ROUTING_NAME1="ROUTING_SPRING_BOOT_DELAY1";


    @Bean
    public CustomExchange topicExchangeDelay(){
        Map<String,Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type","direct");
        CustomExchange topicExchange = new CustomExchange(EXCHANGE_NAME,"x-delayed-message",false,false,arguments);
        return topicExchange;
    }

    @Bean
    public Queue queueDelay(){
        return new Queue(QUEUE_NAME);
    }

    @Bean
    public Binding bindingDelay(){
        return BindingBuilder.bind(queueDelay()).to(topicExchangeDelay()).with(ROUTING_NAME).noargs();
    }

    @Bean
    public Queue queueDelay1(){
        return new Queue(QUEUE_NAME1);
    }

    @Bean
    public Binding bindingDelay1(){
        return BindingBuilder.bind(queueDelay1()).to(topicExchangeDelay()).with(ROUTING_NAME1).noargs();
    }

//    @Bean
//    public RabbitTemplate rabbitTemplate(RabbitTemplateConfigurer configurer, ConnectionFactory connectionFactory) {
//        RabbitTemplate template = new RabbitTemplate();
//        configurer.configure(template, connectionFactory);
//        //使用json序列化对象
//        template.setMessageConverter(new Jackson2JsonMessageConverter());
//        return template;
//    }
}